import 'dart:io';

import 'package:flutter/material.dart';

///自定义使用hero动画的组件框架
class PhotoHero extends StatelessWidget {
  final bool isNetFile;

  ///附件尺寸
  final double? width;
  final double? height;

  ///附件来源
  final File? photo;
  final String? netUrl;

  ///用于跳到全屏图片显示的回调
  final VoidCallback? onTap;

  const PhotoHero(this.isNetFile,
      {Key? key, this.photo, this.onTap, this.width, this.height, this.netUrl})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: width,
      height: height,
      child: isNetFile
          ? getNetworkFile()
          : getLocalUrl(),
    );
  }

  ///network
  Widget getNetworkFile() {
    return Hero(
      tag: netUrl!,
      child: Material(
        color: Colors.transparent,
        child: InkWell(
          onTap: onTap,
          child: Image.network(
            netUrl!,
            fit: BoxFit.fill,
          ),
        ),
      ),
    );
  }

  ///local
  Widget getLocalUrl(){
    return Hero(
      tag: photo!,
      child: Material(
        color: Colors.transparent,
        child: InkWell(
          onTap: onTap,
          child: Image.file(
            photo!,
            fit: BoxFit.fill,
            //fit: BoxFit.fill,
          ),
        ),
      ),
    );
  }

}
